<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use App;
use DB;
use Laravel\Passport\Events\RefreshTokenCreated;

class PruneOldTokens implements ShouldQueue
{

    public $queue = 'passport';

    /**
     * Create the event listener.
     */
    public function __construct()
    {
    }

    /**
     * Handle the event.
     *
     * @param  RefreshTokenCreated $event
     * @return void
     */
    public function handle(RefreshTokenCreated $event)
    {
        if (App::environment() == 'production')

            DB::table('oauth_refresh_tokens')
                ->where('id', '<>', $event->refreshTokenId)
                ->where('access_token_id', '<>', $event->accessTokenId)
                ->delete();
    }
}
